package com.liangzhong.model.techBar
{
	import com.liangzhong.errortip.ErrorTips;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.playerCenter.vo.PlayerVo;
	import com.liangzhong.model.techBar.vo.TechBarInfoVo;
	
	import flash.utils.ByteArray;
	
	import lz.controls.Alert;

	/**
	 *服务器数据返回解析   
	 * @author lake
	 * 
	 */	
	public class TechBarServerDataParse
	{
		public function TechBarServerDataParse()
		{
		}
		/**
		 * 读取升级返回数据
		 * @param data
		 * 
		 */		
		public static function readGradeUp(data : ByteArray):Object
		{
			var resObj :Object = new Object();
			resObj.retcode 		= data.readInt();//返回码
			if(resObj.retcode == 0)
			{
				var baseInfo :TechBarInfoVo = AppData.getInstance().techBarManager.techBarInfoVo;
				baseInfo.level 		= data.readByte();
				baseInfo.coin 		= data.readUnsignedInt();
				baseInfo.rebate		= data.readShort();
				var curtime :Number = AppData.getInstance().time;
				baseInfo.pretime = curtime;
				Alert.showErrorTip("升级成功");
			}
			else
			{
				Alert.showErrorTip(ErrorTips.instance.getCErrorTip(resObj.retcode) + "");
			}
			return resObj;
		}
		/**
		 * 读取装备合成返回数据
		 * @param data
		 * 
		 */		
		public static function readEquipCombine(data : ByteArray):Object
		{
			var resObj :Object = new Object();
			resObj.retcode 		= data.readInt();//返回码
			if(resObj.retcode == 0)
			{
				resObj.pid 		= data.readInt();//道具ID
				resObj.ntype 	= data.readByte();//道具类型： GoodsType
				if(resObj.pid > 0)
				{
					//Alert.showErrorTip("装备合成成功");
				}
				else
				{
					//Alert.showErrorTip("装备合成失败");
				}
			}
			else
			{
				Alert.showErrorTip(ErrorTips.instance.getCErrorTip(resObj.retcode) + "");
			}
			return resObj;
		}
		/**
		 * 读取材料合成返回数据
		 * @param data
		 * 
		 */		
		public static function readMaterialCombine(data : ByteArray):Object
		{
			var resObj :Object = new Object();
			resObj.retcode 		= data.readInt();//返回码
			if(resObj.retcode == 0)
			{
				resObj.pid 		= data.readInt();//道具ID
				resObj.ntype 	= data.readByte();//道具类型： GoodsType
				if(resObj.pid > 0)
				{
					//Alert.showErrorTip("材料合成成功");
				}
				else
				{
					//Alert.showErrorTip("材料合成失败");
				}
			}
			else
			{
				Alert.showErrorTip(ErrorTips.instance.getCErrorTip(resObj.retcode) + "");
			}
			return resObj;
		}
		/**
		 * 读取球员合成返回数据
		 * @param data
		 * 
		 */		
		public static function readPlayerCombine(data : ByteArray):Object
		{
			var resObj :Object = new Object();
			resObj.retcode 		= data.readInt();//返回码
			if(resObj.retcode == 0)
			{
				resObj.pid 		= data.readInt();//道具ID
				resObj.ntype 	= data.readByte();//道具类型： GoodsType
				if(resObj.pid > 0)
				{
					//Alert.showErrorTip("球员合成成功");
				}
				else
				{
					//Alert.showErrorTip("球员合成失败");
				}
			}
			else
			{
				Alert.showErrorTip(ErrorTips.instance.getCErrorTip(resObj.retcode) + "");
			}
			return resObj;
		}
		/**
		 * 读取球衣合成返回数据
		 * @param data
		 * 
		 */		
		public static function readClothCombine(data : ByteArray):Object
		{
			var resObj :Object = new Object();
			resObj.retcode 		= data.readInt();//返回码
			if(resObj.retcode == 0)
			{
				resObj.pid 		= data.readInt();//道具ID
				resObj.ntype 	= data.readByte();//道具类型： GoodsType
				if(resObj.pid > 0)
				{
					//Alert.showErrorTip("球衣合成成功");
				}
				else
				{
					//Alert.showErrorTip("球衣合成失败");
				}
			}
			else
			{
				Alert.showErrorTip(ErrorTips.instance.getCErrorTip(resObj.retcode) + "");
			}
			return resObj;
		}
		/**
		 * 读取球员洗练返回数据
		 * @param data
		 * 
		 */		
		public static function readPlayerRefresh(data : ByteArray):Object
		{
			var resObj :Object = new Object();
			resObj.retcode 		= data.readInt();//返回码
			if(resObj.retcode == 0)
			{
				resObj.playerid 	= data.readInt();//球员ID
				resObj.starid 		= data.readInt();//球星ID
				if(resObj.playerid > 0)
				{
					AppData.getInstance().playerCenterDataManager.initPlayerInfo(resObj.playerid);
					//Alert.showErrorTip("球员洗练成功");
				}
				else
				{
					//Alert.showErrorTip("球员洗练失败");
				}
			}
			else
			{
				Alert.showErrorTip(ErrorTips.instance.getCErrorTip(resObj.retcode) + "");
			}
			return resObj;
		}
		/**
		 * 读取角色转职返回数据
		 * @param data
		 * 
		 */		
		public static function readRoleChange(data : ByteArray):Object
		{
			var resObj :Object = new Object();
			resObj.retcode 		= data.readInt();//返回码
			if(resObj.retcode == 0)
			{
				var p :PlayerVo = AppData.getInstance().playerCenterDataManager.getSelfInfo();
				if(p)
				{
					p.ability 	= data.readShort();
					p.place 	= data.readByte();
					p.attack 	= data.readShort();
					p.defence 	= data.readShort();
					p.steal 	= data.readShort();
					p.power 	= data.readShort();
					p.speed 	= data.readShort();
					p.control 	= data.readShort();
					p.level 	= 1;
					p.turnPlace();
				}
				//Alert.showErrorTip("转职成功");
			}
			else
			{
				Alert.showErrorTip(ErrorTips.instance.getCErrorTip(resObj.retcode) + "");
			}
			return resObj;
		}
		/**
		 * 读取角色强化返回数据
		 * @param data
		 * 
		 */		
		public static function readRoleRefresh(data : ByteArray):Object
		{
			var resObj :Object = new Object();
			resObj.retcode 		= data.readInt();//返回码
			if(resObj.retcode == 0)
			{
				var p :PlayerVo = AppData.getInstance().playerCenterDataManager.getSelfInfo();
				var color :int;
				if(p)
				{
					color = data.readByte();
					if(color > p.color)
					{
						p.maxphysical ++;
					}
					resObj.color = color;
					if(color > 0)
					{
						p.color 	= color;
						p.ability 	= data.readShort();
						p.attack 	= data.readShort();
						p.defence 	= data.readShort();
						p.steal 	= data.readShort();
						p.power 	= data.readShort();
						p.speed 	= data.readShort();
						p.control 	= data.readShort();
						//Alert.showErrorTip("强化成功");
					}
					else
					{
						//Alert.showErrorTip("强化失败");
					}
				}
				else
				{
					Alert.showErrorTip("球员中心数据异常");
				}
			}
			else
			{
				Alert.showErrorTip(ErrorTips.instance.getCErrorTip(resObj.retcode) + "");
			}
			return resObj;
		}
	}
}